package com.it.sun.esaychat.file.controller;


import com.it.sun.easychat.model.util.ResultHelper;
import com.it.sun.easychat.model.vo.FileVO;
import com.it.sun.easychat.model.vo.ResultVO;
import com.it.sun.esaychat.file.service.IFileServices;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author sunmannian
 * @since 2020-05-28
 */
@RestController
@RequestMapping("/file")
public class FileController {

    @Autowired
    private IFileServices fileServices;

    @PostMapping("/upload")
    @ApiOperation("上传文件")
    public ResultVO<FileVO> upload(MultipartFile file) {
        FileVO fileVO = fileServices.upload(file);
        return ResultHelper.getSuccess(fileVO);
    }

    @PostMapping("/batchUpload")
    @ApiOperation("批量上传文件")
    public ResultVO<List<FileVO>> upload(List<MultipartFile> files) {
        List<FileVO> fileVOS = fileServices.batchUpload(files);
        return ResultHelper.getSuccess(fileVOS);
    }
}

